/*
 * @Description: 
 * @Version: 2.0
 * @Autor: 张磊
 * @Date: 2020-11-10 15:41:40
 * @LastEditors: 张磊
 * @LastEditTime: 2020-11-13 23:14:39
 * @FilePath: \lht1802A\项目代码\rank_tree\src\store\modules\home.js
 */
import {
  getTab,
  getBan,
  getClassList,
  getVudioList,
  getDetailList,
  getrankPage,
  getDropList,
  // getHomeAd

} from '@/api/index'
const state = {
  navList: [],
  img: '',
  classList: [],
  cityList: [],
  vudioList: [],
  detailList: [],
  rankingData: [],
  cityData: [],
}
const mutations = {
  saveData(state, payload) {
    //console.log(payload,2222);
    let arr = []
    payload.forEach(v => {
      state.cityData.rankItemList.forEach((vv, index) => {
        if (vv.name == v) {
          vv.name = '';
          arr.push(index)
        }
      })

    })
    console.log(state.cityData.rankItemList, '我就去了', arr)
    state.rankingData.forEach(item => {
      item.scores.forEach((vv, index) => {
        console.log(222222)
        if (arr.includes(index)) {
          console.log(2, vv)
          vv.score = ''
        }
      })
    })
    // state.cityData.rankItemList = []
  },
  updateData(state, payload) {
    console.log(payload, 'oop')
    state.cityData.rankItemGroup.forEach(v => {
      v.list.forEach(vv => {
        if (vv.id == payload.id) {
          vv.islight = true
        }
        // payload.forEach(m=>{})

      })
    });
  },
  getRanking(state, payloay) {
    state.rankingData = payloay;
    //    console.log(payloay,'aaaaaaaaaaaaaaaaaa');
    payloay.forEach(v => {
      //   console.log(v,'bbbbbbbbbbbbbbbbb');
      let num = 0;
      v.scores.forEach(vv => {
        // console.log(vv,'wdaid')
        num = num * 1 + vv.score * 1
      });
      v['pai'] = num
    })

    state.rankingData = state.rankingData.sort((a, b) => {
      return b.pai - a.pai
    })
    // console.log(state.rankingData,999666);
  },
  updateCategoryList(state, payload) {
    state.rankCategoryList = payload;
  },
  getCity(state, payload) {
    state.cityData = payload;
    state.cityData.rankItemGroup.forEach(v => {
      v.list.forEach(vv => {
        vv['islight'] = false
      })
    });
    console.log('的文件OA为大家哦', state.cityData.rankItemGroup)
  },



  getTab(state, val) {

    state.navList = val
  },
  getBan(state, val) {
    state.img = val

  },
  getClassList(state, val) {
    state.classList = val
  },
  getCityList(state, val) {
    state.cityList = val
  },
  getVudioList(state, val) {
    state.vudioList = val
  },
  // getDetailList(state, val) {
  //   state.detailList = val
  // },
  getrankPage(state, val) {
    state.rankPage = val
  },

  getDetailList(state, val) {
    state.rankingData = val
  },
  getDropList(state, val) {
    state.cityData = val
  }
}
const actions = {
  async getTab({
    commit
  }, val) {
    let res = await getTab(val)
    console.log(res.rankCategoryList);
    commit('getTab', res.rankCategoryList)
  },
  async getBan({
    commit
  }, val) {
    let res = await getBan(val)
    commit('getBan', res.carouselList[0].image)
  },
  async getClassList({
    commit
  }, val) {
    let res = await getClassList(val)
    // console.log(res.data,'zzzz');
    commit('getClassList', res.dataList)
  },
  async getCityList({
    commit
  }, val) {
    let res = await getClassList(val)
    // console.log(res.data,'zzzz');
    commit('getCityList', res.dataList)
  },
  async getVudioList({
    commit
  }, val) {
    let res = await getVudioList(val)
    // console.log(res.data,'zzzz');
    commit('getVudioList', res.dataList)
  },
  async getDetailList({
    commit
  }, val) {
    let res = await getDetailList(val)
    console.log(res, 'qqqqqq');
    commit('getRanking', res.rankDataList)
  },
  async getrankPage({
    commit
  }, val) {
    let aa = await getrankPage(val)
    console.log(val)
    console.log(aa)
    commit('getrankPage', aa.dataList)
  },
  async getDropList({
    commit
  }, val) {
    let res = await getDropList(val)
    console.log(val, 'zzzz');
    commit('getCity', res)
  },

}
const modules = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  modules
}
